<!DOCTYPE html>
<html>
	<head>
	    <title>各种查询参数示例</title>
	    <meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!-- 所有的 css & js 资源 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
		<link rel="stylesheet" href="../../static/sa.css"> 
		<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
		<script src="https://unpkg.com/element-ui@2.13.0/lib/index.js"></script>
		<script src="https://unpkg.com/http-vue-loader@1.4.2/src/httpVueLoader.js"></script>
		<script src="https://unpkg.com/jquery@3.4.1/dist/jquery.min.js"></script>
		<script src="https://www.layuicdn.com/layer-v3.1.1/layer.js"></script>
		<script src="../../static/sa.js"></script>
        <style>
			.td-img{width: 180px; height: 90px; cursor: pointer; vertical-align: middle;}
			.c-panel-add .td-img{width: 200px;}
			.c-panel-add .el-form .el-input{width: 200px;}
        </style>
	</head>
	<body>
		<div class="vue-box" style="display: none;" :style="'display: block;'">
			<div class="c-panel">
				<!-- ------------- 检索参数 ------------- -->
				<div class="c-title">检索参数</div>
				<el-form @submit.native.prevent >
					<sa-item name="标题搜索" v-model="p.title"></sa-item>
					<el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
				</el-form>
				<!-- ------------- 快捷curd按钮 ------------- -->
				<sa-item type="fast-btn" show="add,delete,export,reset"></sa-item>
				<!-- ------------- 数据列表 ------------- -->
				<el-table class="data-table" ref="data-table" :data="dataList" size="small">
					<sa-td type="selection"></sa-td>
					<sa-td name="编号" prop="id" width="70px"></sa-td>
					<el-table-column label="图片" width="400px">
						<template slot-scope="s">
							<img :src="s.row.img_src" class="td-img" title="点击预览" @click="sa.showImage(s.row.img_src)">
							<span style="color: #666; padding-left: 0.5em;"> 点击预览</span>
						</template>
					</el-table-column>
					<sa-td name="标题" prop="title"></sa-td>
					<sa-td name="排序" prop="sort"></sa-td>
					<sa-td name="点击量" prop="click_count"></sa-td>
					<sa-td name="状态" prop="status" type="switch" :jv="{1: '显示', 2: '隐藏'}"></sa-td>
					<sa-td name="创建时间" prop="create_time" type="datetime"></sa-td>
					<el-table-column label="操作" width="180px">
						<template slot-scope="s">
							<el-button class="c-btn" type="primary" icon="el-icon-edit" @click="update(s.row)">修改</el-button>
							<el-button class="c-btn" type="danger" icon="el-icon-delete" @click="del(s.row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
				<!-- ------------- 分页 ------------- -->
				<sa-item type="page" :curr.sync="p.pageNo" :size.sync="p.pageSize" :total="dataCount" @change="f5()"></sa-item>
			</div>		
		</div>
		<!-- 模拟数据 -->
		<script src="mock-data-list.js"></script>
        <script>
			var app = new Vue({
				components: {
					"sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),		
					"sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue'),			
				},
				el: '.vue-box',
				data: {
					sa: sa, 	// 超级对象
					p: {		// 查询参数
						pageNo: 1,
						pageSize: 10,
						title: '',
						sortType: 0
					},
					dataCount: 0,
					dataList: [],	// 数据集合
				},
				methods: {
					// 刷新
					f5: function(){
						sa.ajax2('/SysSwiper/getList', this.p, function(res){
							this.dataList = res.data;	// 数据
							this.dataCount = res.dataCount;			// 分页 
							sa.f5TableHeight();		// 刷新表格高度 
						}.bind(this), {res: mockDataList});
					},
					// 保存
					add: function(){
						sa.showIframe('新增数据', 'swiper-add.html?id=-1', '580px', '450px');
					},
					// 修改
					update: function(data){
						sa.showIframe('修改数据', 'swiper-add.html?id=' + data.id, '580px', '450px');
					},
					// 删除
					del: function(data){
						sa.confirm('是否删除，此操作不可撤销', function(){
							sa.ajax2('/SysSwiper/delete?id=' + data.id, function(res){
								sa.ok('删除成功');
								sa.arrayDelete(this.dataList, data);
								sa.f5TableHeight();		// 刷新表格高度 
							}.bind(this))
						}.bind(this))
					},
					// 批量删除
					deleteByIds: function() {
						// 获取选中元素的id列表
						let selection = this.$refs['data-table'].selection;
						let ids = sa.getArrayField(selection, 'id');
						if(selection.length == 0) {
							return sa.msg('请至少选择一条数据')
						}
						// 提交删除 
						sa.confirm('是否批量删除选中数据？此操作不可撤销', function() {
							sa.ajax2('/SysType/deleteByIds', {ids: ids.join(',')}, function(res) {
								sa.arrayDelete(this.dataList, selection);
								sa.ok('删除成功');
								sa.f5TableHeight();		// 刷新表格高度 
							}.bind(this))
						}.bind(this));
					},
				},
				created: function(){
					this.f5();
					sa.onInputEnter();		// 监听输入框的回车事件，执行查询  
				}
			})
			
		</script>
</html>